<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SkyeIntelligence - Login</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="../admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="../admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../admin/css/animate.css" rel="stylesheet">
    <link href="../admin/css/style.css?v=4.0.0" rel="stylesheet">
    <base target="_blank">
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if(window.top !== window.self){ window.top.location = window.location;}
        </script>
</head>

<body class="gray-bg">
    <div class="middle-box text-center loginscreen  animated fadeInDown">
        <div>
            <h1 class="logo-name">Skye</h1>
        </div>
        <h3>欢迎使用</h3>
        <form action="./login" id="loginForm">
            <div class="form-group">
                <input id='inputUserName' name="userName" class="form-control" placeholder="用户名" value="">
            </div>
            <div class="form-group">
                <input id='inputPwd' name="password" type="password" class="form-control" placeholder="密码" value="">
            </div>
            <button id='btnLogin' type="submit" class="btn btn-primary block full-width m-b">登 录</button>
        </form>
    </div>

    <!-- 全局js -->
    <script src="../admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="../admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="../admin/js/plugins/layer/layer.min.js"></script>
    <script src="../admin/js/jquery.form.js"></script>
    <script type="text/javascript">
        $(function(){  
          var _LoadIndex =undefined;//是否正在登录；

           //登录表单异步提交
           $("#loginForm").submit(function(e){
            e.preventDefault();
                $(this).ajaxSubmit({
                    type:"post",
                    url: this.action,   
                    // beforeSerialize:function,             
                    beforeSubmit: beforeSubmit,// return false to cancel submit            
                    clearForm: false,//当提交成功后，是否清空form。
                    //data: { key1: 'value1', key2: 'value2' },//自定义参数
                    success: success,
                    // replaceTarget:true,
                    // target: "#target",
                    error: function(err){
                        layer.close(_LoadIndex);
                        layer.alert("system error!",{icon:2});
                        console.log('err');
                    }
                });                
            });
    });

    //表单提交前校验
    function beforeSubmit(arr,$form,options){    
       var userName= $('#inputUserName').val();
       var password= $('#inputPwd').val();
       var canLogin =  true ;
       if($.trim(userName).length == 0){
        layer.tips('请输入用户名！', '#inputUserName', { 
         tips: [2, '#3595CC'],
         time: 4000,
         tipsMore: true
     });
        $('#inputUserName').focus();
        canLogin = false;
    }
    if($.trim(password).length==0){
        layer.tips('请输入密码！', '#inputPwd', {
            tips: [2, '#3595CC'],
            time: 4000,
            tipsMore: true
        });
        $('#inputPwd').focus();
        canLogin = false;
    }
    if(!canLogin)
        return false;
     _LoadIndex = layer.load(1);
}

    //表单提交成功事件
    function success(data){
        layer.close(_LoadIndex);
        if(data.code==1){
            layer.msg(data.msg,{icon:1,time:1500}); 
            location.href='/mc';
        }
        else if((data.code==-1)){
            layer.alert(data.msg, {icon:2, title:"提示"}); 
        }else{
            layer.alert("system error!"); 
        }
    }       
</script>

</body>

</html>